package com.kx.demo.concurrent;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author kx
 */
public class AtomicIntegerDemo {

    static int i = 0;
    static AtomicInteger j = new AtomicInteger();

    public static void main(String[] args) {

        synchronizedAdd();
        try {
            Thread.sleep(1 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(i);

    }

    public static void synchronizedAdd() {
        for (int i1 = 0; i1 < 100; i1++) {
            new Thread() {
                @Override
                public void run() {
                    // 10个线程失去意义
//                    synchronized (this) {
                        j.incrementAndGet();
                        System.out.println(j);
//                    }
                }
            }.start();
        }
    }

}
